﻿using System;
using BEGDC.CC.BL.Workflow;
using BEGDC.CC.BL.Common;
using BEGDC.CC.BL.Common.Query;
using BEGDC.Utility.Castle;
using BEGDC.CC.Entity;

namespace BEGDC.CC.Web.UserControls
{
	/// <summary>
	/// Summary description for EVAccessControl.
	/// </summary>
	public class EVAccessControl : AccessControl
	{
		public EVAccessControl()
		{
			//
			// TODO: Add constructor logic here
			//
		}

		public override bool IsReadOnly
		{
			get
			{
				if( base.IsReadOnly )
				{
					return base.IsReadOnly;
				}
				else
				{
					if( this._currentStep == WorkTransition.EV_CATApproveMM || this._currentStep == WorkTransition.EV_CATDirectorApprove
						|| this._currentStep == WorkTransition.EV_CODStaffCheckMM || this._currentStep == WorkTransition.EV_MeetingMinutes
						|| this._currentStep == WorkTransition.EV_PSOApprove || this._currentStep == WorkTransition.EV_PSOApproveMM || this._currentStep == WorkTransition.EV_Close )
					{
						return true;
					}
					else
						return false;
				}
			}
		}

		public override bool IsAttachmentReadOnly
		{
			get
			{
				if( this._currentStep == WorkTransition.EV_CATApproveMM || this._currentStep == WorkTransition.EV_CATDirectorApprove
					|| this._currentStep == WorkTransition.EV_CODStaffCheckMM || this._currentStep == WorkTransition.EV_MeetingMinutes
					|| this._currentStep == WorkTransition.EV_PSOApprove || this._currentStep == WorkTransition.EV_PSOApproveMM )
				{
					return true;
				}
				else if(this._currentStep == WorkTransition.End && this._state!=SysDicItem.ProjectStatusFlag.Archive)
				{
					if(_state == SysDicItem.ProjectStatusFlag.Participation)
						return !this._isMgrOrStaff;
					else
						return true;
				}
				else
					return base.IsAttachmentReadOnly;
			}
		}

		public bool IsReadOnlyForApp
		{
			get
			{
				return base.IsReadOnly;
			}
		}


		public override bool IsButtonVisible(string name)
		{
			if(this.IsQuery)
			{
				switch(name)
				{
					case CVTransitionList.Copy:
						return this.ShowCopyButton();
						break;
					case CVTransitionList.Reply:
						return this.ShowReplyButton();
						break;
					case CVTransitionList.Save:
						return this.ShowSaveButton();
						break;
					default:
						return false;
				}
			}
			else
			{
				switch(name)
				{
					case EVTransitionList.Save:
						return this.ShowSaveButton();
						break;
					case EVTransitionList.Copy:
						return this.ShowCopyButton();
						break;
					case EVTransitionList.Reply:
						return this.ShowReplyButton();
						break;
					default:
					switch(this._currentStep)
					{
						case WorkTransition.Draft: //new ev application
							if( name == EVTransitionList.Submit )
								return true;
							else
								return false;
						case WorkTransition.EV_Request:
							if(name == EVTransitionList.Submit)
								return true;
							else
								return false;
						case WorkTransition.EV_ReRequest:
							if(name == EVTransitionList.Submit)
								return true;
							else
								return false;
						case WorkTransition.EV_Assign:
							if(name == EVTransitionList.Assign || name == EVTransitionList.Reject 
								|| name == EVTransitionList.Check || name == EVTransitionList.Query)
								return true;
							else
								return false;
						case WorkTransition.EV_Check:
							if( name == EVTransitionList.Submit || name == EVTransitionList.Reject
								|| name == EVTransitionList.Query )
								return true;
							else
								return false;
						case WorkTransition.EV_CATDirectorApprove:
							if( name == EVTransitionList.Reject || name == EVTransitionList.Approve || name == EVTransitionList.Query)
								return true;
							else
								return false;
						case WorkTransition.EV_PSOApprove:
							if( name == EVTransitionList.Reject || name == EVTransitionList.Approve || name == EVTransitionList.Query)
								return true;
							else
								return false;
						case WorkTransition.EV_MeetingMinutes:
							if( name == EVTransitionList.Submit )
								return true;
							else
								return false;
						case WorkTransition.EV_CODStaffCheckMM:
							if( name == EVTransitionList.Check || name == EVTransitionList.Reject || name == EVTransitionList.Query )
								return true;
							else
								return false;
						case WorkTransition.EV_CATApproveMM:
							if( name == EVTransitionList.Approve || name == EVTransitionList.Reject)
								return true;
							else
								return false;
						case WorkTransition.EV_PSOApproveMM:
							if( name == EVTransitionList.Approve || name == EVTransitionList.Reject)
								return true;
							else
								return false;
						case WorkTransition.EV_Close:
							if( name == EVTransitionList.Close || name == EVTransitionList.Query)
								return true;
							else
								return false;
					}
						return false;
						break;
				}
			}
		}

	}
}
